package jsd2204.bookstore.bookserver.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jsd2204.bookstore.bookserver.pojo.dto.CommentDTO;
import jsd2204.bookstore.bookserver.pojo.vo.BookStandardVO;
import jsd2204.bookstore.bookserver.pojo.vo.ComsStandardVO;
import jsd2204.bookstore.bookserver.pojo.vo.ReadTestStandardVO;
import jsd2204.bookstore.bookserver.service.impl.BookServiceImpl;
import jsd2204.bookstore.bookserver.service.impl.CommentServiceImpl;
import jsd2204.bookstore.bookserver.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jiale
 * @version 1.0
 * @description这是书籍的控制类
 * @date 2022/07/31 23:25
 **/
@Api(tags = "评论管理模块")
@Slf4j
@RestController
public class CommentController {
    @Autowired
    private CommentServiceImpl service;

    @PostMapping("/comment")
    @ApiOperation("插入评论信息")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentDTO", value = "书籍的评论对象", dataType = "CommentDTO", required = true)
    })
    public JsonResult comment(CommentDTO commentDTO) {
        log.debug("评论对象:" + commentDTO);
        service.comment(commentDTO);
        return JsonResult.ok();
    }

    @GetMapping("/comsById")
    @ApiOperation("获取评论信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要查询评论的id", dataType = "long", required = true)
    })
    public JsonResult<List<ComsStandardVO>> comsById(Long id) {
        List<ComsStandardVO> comsStandardVOList = service.comsByID(id);
        JsonResult<List<ComsStandardVO>> jsonResult=new JsonResult();
        jsonResult.setData(comsStandardVOList);
//        log.debug("查询的评论对象："+comsStandardVOList);
        return jsonResult;
    }
    @GetMapping("/commentDelete")
    @ApiOperation("删除评论信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的id", dataType = "long", required = true)
    })
    public JsonResult commentDeleteById(Long id) {
        log.debug("参数id:"+id);
        service.commentDeleteById(id);
        return JsonResult.ok();
    }
}
